﻿using GENERIC.Repository.Tests.Models;
using GENERIC.Respository.Interfaces;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Objects;
using System.Linq;
using System.Text;

namespace GENERIC.Repository.Tests
{
    public class MokeContext : IContext
    {
        #region Attributs

        private IGENERICSet<Customer> _Customers;

        private IGENERICSet<Order> _Orders;

        #endregion
        
        #region Properties

        private IGENERICSet<Customer> Customers
        {
            get
            {
                if (_Customers == null)
                {
                    _Customers = new MokeSet<Customer>();
                    _Customers.Insert(new Customer() { Id = 1, Name = "Dupont" });
                    _Customers.Insert(new Customer() { Id = 2, Name = "Durand" });
                }
                return _Customers;
            }
        }

        private IGENERICSet<Order> Orders
        {
            get
            {
                if (_Orders == null) _Orders = new MokeSet<Order>();
                return _Orders;
            }
        }

        #endregion

        #region Methods

        public IGENERICSet<TEntity> CreateSet<TEntity>() where TEntity : class, new()
        {
            if (typeof(TEntity) == typeof(Customer)) return Customers as IGENERICSet<TEntity>;
            if (typeof(TEntity) == typeof(Order)) return Orders as IGENERICSet<TEntity>;
            throw new NotImplementedException();
        }

        public void SaveChanges()
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            _Customers = null;
            _Orders = null;
        }

        #endregion


        public ITransaction BeginTransaction()
        {
            throw new NotImplementedException();
        }
    }
}
